<?php

	// +----------------------------------------------------------------------
	// | Foreign控制器
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\controller\cms;

	use app\model\cms\Message;
	use app\model\cms\Advert;
	use think\Config;

	class Foreign extends Common
	{

		/**
		 * 获取广告位信息
		 * @param unknown $name
		 * @return string
		 */
		public function advert($name)
		{
			// 设置状态
			Config::set('app_trace', false);
			return 'document.write(\'' . Advert::getHtmlAdvert($name) . '\');';
		}

		public function test()
		{
			return $this->fetch();
		}

		public function sitemap()
		{
			$category = $this->category();
			$this->assign('category', $category);

			return $this->fetch();
		}

		/**
		 * 网站地图
		 */
		public function map()
		{
			return $this->fetch();
		}

		public function join()
		{
			/* 分类信息 */
			$category = $this->category();
			$this->assign('category', $category);

			return $this->fetch();
		}

		public function message()
		{
			if ($this->request->isPost()) {
				if (!geetest_check($this->request->post())) {
					$this->error('验证码错误');
				}
				$result = $this->validate($this->request->post(), 'Message.add');
				if (true !== $result) {
					$this->error($result);
				} else {
					$message = new Message();
					$message->name = $this->request->post('name');
					$message->phone = $this->request->post('phone');
					$message->content = $this->request->post('content');
					$message->email = $this->request->post('email');
					if (!$message->save()) {
						$this->error($message->getError());
					} else {
						// action_log('message_add','message',$user['id'],$user['id']);
						$this->success('留言成功');
					}
				}
			} else {
				/* 分类信息 */
				$category = $this->category();
				$this->assign('category', $category);

				return $this->fetch();
			}
		}
	}
